package xyz.xxpc.springcloud.consumer.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import xyz.xxpc.springcloud.pojo.User;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    private static final String URL = "http://PROVIDER-30080/user";
    private RestTemplate restTemplate;

    @Autowired
    public void setRestTemplate(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @Override
    public List<User> queryAll() {
        return restTemplate.getForObject(URL, List.class);
    }

    @Override
    public User query(Integer id) {
        return restTemplate.getForObject(URL + "/" + id, User.class);
    }

    @Override
    public User add(User user) {
        return restTemplate.postForObject(URL, user, User.class);
    }
}
